class Solution(object):
    def longestPalindrome(self, s):
        """
        :type s: str
        :rtype: str
        """
        # the odd condition
        maxBegin, maxEnd = 0, -1
        for i in range(len(s)):
            begin = i
            end = i
            while begin>=0 and end<len(s):
                if s[begin]==s[end]:
                    if (end-begin)>(maxEnd-maxBegin):
                        maxBegin=begin
                        maxEnd=end
                    begin-=1
                    end+=1
                else:
                    break
        # even condition
        for i in range(len(s)-1):
            begin = i
            end = i+1
            while begin>=0 and end<len(s):
                if s[begin]==s[end]:
                    if (end-begin)>(maxEnd-maxBegin):
                        maxBegin=begin
                        maxEnd=end
                    begin-=1
                    end+=1
                else:
                    break
        return s[maxBegin:maxEnd+1]

print(Solution().longestPalindrome("aaaaa"))